﻿// 1.1.7.20. Write a program, which checks whether there is a subset of given array of N elements, which has a sum S.
// The numbers N, S and the array values are read from the console. Same number can be used many times.
// Example: {2, 1, 2, 4, 3, 5, 2, 6}, S = 14 -> yes (1 + 2 + 5 + 6 = 14)

using System;
using System.Collections.Generic;

class SubsetSum
{
    static void Main()
    {
        long s = 14;    //long s = long.Parse(Console.ReadLine());
        //long n = long.Parse(Console.ReadLine());
        long[] userInput = new long[] { 2, 1, 2, 4, 3, 5, 2, 6 } ;

        //for (int i = 0; i < n; i++)
        //{
        //    userInput[i] = long.Parse(Console.ReadLine());
        //}
        int maxI = (int)Math.Pow((double)2, userInput.GetLength(0)) - 1;
        List<long> listy = new List<long>();
        for (int i = 1; i <= maxI; i++)
        {
            listy.Clear();
            long currentSubsetSum = 0;
            for (int j = 0; j < userInput.GetLength(0); j++)
            {
                int mask = 1 << j;
                int nAndMask = i & mask;
                int bitOnJ = nAndMask >> j;
                if (bitOnJ == 1)
                {
                    currentSubsetSum += userInput[j];
                    listy.Add(userInput[j]);
                }
            }
            if (currentSubsetSum == s)
            {
                Console.WriteLine("yes ({0} = {1})", string.Join(" + ", listy), s);
                //Console.WriteLine("yes " + "(" + string.Join(" + ", listy) + " = " + s +")");
                //return;
            }
        }
    }
}
